************************************************************************
*   Project: The Media Smells like Sulfur!!! Leaders and Verbal        *
*            Attacks against the Fourth Estate in Unconsolidated       *
*            Democracies                                               *
*   Authors: JA Solis & I Sagarzazu                                    *
*   Task: Replication Materials for Political Communication article    *
*   Stata version: 15.1 IC                                             *     
*   Last updated: 8/15/2019                                            *
************************************************************************

*NOTE: This .do file produces the following analyses for:
*      ->Manuscript: Figure 1, Figure 3
*      ->Appendix  : Table 2,  Figure 4, Figure 5

*Set working directory
cd "C:\Users\Jonathan A. Solis\Dropbox\SagarzazuSolis\final manuscript"

*----------------------------------------------------------*
* Figure 1: Frequency of Al´o Presidente shows per quarter *
*----------------------------------------------------------* 

*Load raw data on AP episodes
clear
import delimited "ap_episodes.csv"

*Prep date for figure
gen d=date(date,"DMY")
format d %td
gen quarter = quarter(d)
gen year = year(d)

*Preserve data
preserve

*Collapse to create count
gen one=1
collapse (sum) one, by(quarter year)

*Graph figure
twoway dropline one quarter, by(year) ylabel(0(4)16) scheme(lean2) ytitle("Shows per quarter") xtitle("Quarter")

*Restore data
restore

*Further stylized by hand for manuscript

*-----------------------------------------------------*
* Figure 3: Bar Chart and Box Plots of Verbal Attacks *
*-----------------------------------------------------* 
clear
import delimited "polcom_rep_ap" 

*First: create identifier
gen category=.
replace category=2 if non_inst==1
replace category=1 if inst==1
replace category=0 if category==.

*check new variable
sum category

*Second: Grab data to add to figure once made*

*Basic analysis
sum(attack_sent) if category==0
display r(sum)
*total=1661
*mean=39.54762, (n=42)

sum(attack_sent) if category==1
display r(sum)
*total=120
*mean=20, (n=20)

sum(attack_sent) if category==2
display r(sum)
*524
*mean=131, (n=4)

*Third: Create bar graph (Fig 3a)*
graph bar (mean) attack_sent, over(category) blabel(total) ascat nofill ///
bargap(-30) ///
ytitle("Verbal Attacks Average") ylab(,nogrid)  ylabel( 0(25)125,nogrid)  ///
 yvaroptions(relabel(1 "No Critical Events" 2 "Institutional Events" 3 "Non-Institutional Events"))  

*Second: Create box plots (Fig 3b)*
graph box attack_sent, over(category) ascat ///
ytitle("Verbal Attacks Count") ylabel( 0(25)150,nogrid)  ///
yvaroptions(relabel(1 "No Critical Events" 2 "Institutional Events" 3 "Non-Institutional Events"))

*Further stylized by hand for manuscript

************************************************
************************************************
******************* Appendix *******************
************************************************
************************************************

*------------------------------*
* Table 2: Summary Statistics  *
*------------------------------* 

sum attack_sent inst non_inst  cre1999q elect2000q prtst2002q coup2002q ///
strk2002q ref2004q elect2006q cre2007q  cre2009q oil approval inst_rctv ///
 non_inst_rctv prtst2007q gdp_qtr censor harass

*NOTE: Summary statistics for ARIMA residuals taken from analysis in R Script.

*---------------------------------------------------------------------*
* Figure 4: Bar Chart and Box Plots of Verbal Attacks (RCTV analysis) *
*---------------------------------------------------------------------* 

*First: create identifier
gen category_rctv=.
replace category_rctv=2 if non_inst_rctv==1
replace category_rctv=1 if inst_rctv==1
replace category_rctv=0 if category_rctv==.

*check new variable
sum category_rctv

*Second: Grab data to add to figure once made*

*Basic analysis
sum(attack_sent) if category_rctv==0
display r(sum)
*total=1632
*mean=39.80488, (n=41)

sum(attack_sent) if category_rctv==1
display r(sum)
*total=120
*mean=20, (n=20)

sum(attack_sent) if category_rctv==2
display r(sum)
*553
*mean=110.6, (n=5)

*Second: Create bar graph (Fig 4a: Appendix)*
graph bar (mean) attack_sent, over(category_rctv) blabel(total) ascat nofill ///
bargap(-30) ///
ytitle("Verbal Attacks Average") ylab(,nogrid)  ylabel( 0(25)125,nogrid)  ///
 yvaroptions(relabel(1 "No Critical Events" 2 "Institutional Events" 3 "Non-Institutional Events"))  

*Second: Create box plots (Fig 4b: Appendix)*
graph box attack_sent, over(category_rctv) ascat ///
ytitle("Verbal Attacks Count") ylabel( 0(25)150,nogrid)  ///
yvaroptions(relabel(1 "No Critical Events" 2 "Institutional Events" 3 "Non-Institutional Events"))

*Further stylized by hand for manuscript

*-------------------------------------------------*
* Figure 5: Verbal Attacks vs. Non-verbal Attacks *
*-------------------------------------------------* 

*Indicate for State to preserve dataset
preserve

*Collapse by year
collapse (mean) attack_sent (mean) censor_fill harass_fill, by(year)

*Set data to time series
tsset year

*Create labels
label var censor_fill "Censorship Score"
label var harass_fill "Harassment Score"
label var attack_sent "Verbal Attacks"

*Create figure: verbal attacks and harassment
tsline attack_sent /*
*/ || tsline harass_fill, yaxis(2) /*
*/ || tsline censor_fill, yaxis(3) /*
*/ scheme(lean2) legend(pos(6) cols(3)) xlab(1998(2)2012)

*Further stylized by hand for manuscript

*Restore preserved data
restore
